package com.cskaoyan.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/07/18:59
 */
@RestController
public class FileController {

    @Value("${my.path}")
    String path;


    @RequestMapping("project2File/storage/*")
    @ResponseBody
    public byte[] returnFile(HttpServletRequest request) throws IOException {
        String requestURI = request.getRequestURI();
        String s = requestURI.replaceFirst("/", "");
        FileInputStream fileInputStream = new FileInputStream(new File(path + s));
        byte[] bytes = new byte[fileInputStream.available()];
        fileInputStream.read(bytes, 0, fileInputStream.available());
        return bytes;
    }
}
